package com.zeng;

import com.zeng.bean.Person;
import com.zeng.config.MainConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Arrays;

/**
 * @author Zqm
 * @Title: MainTest
 * @ProjectName SpringAnnotationDriven
 * @date 2019/1/10
 */
public class MainTest {



    public static void main(String[] args) {

        /**
         * 传统xml 注入bean
         */
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean.xml");
        Person person = (Person) applicationContext.getBean("person");
        System.out.println("传统xml 注入bean........."+person);

        /**
         * 配置文件注入bean
         */
        ApplicationContext applicationContext1 = new AnnotationConfigApplicationContext(MainConfig.class);
        Person bean = applicationContext1.getBean(Person.class);
        String[] beanNamesForType = applicationContext1.getBeanNamesForType(Person.class);
        Arrays.asList(beanNamesForType).stream().forEach(n -> System.out.println("配置文件注入bean"+n));
        System.out.println(bean);
    }
}
